package com.qingcloud.adminbackend.controller;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qingcloud.adminbackend.anno.CloudApi;
import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.constant.WamingConstant;
import com.qingcloud.adminbackend.controller.open.param.ChangePwdParam;
import com.qingcloud.adminbackend.entity.stationgroup.SysStationGroup;
import com.qingcloud.adminbackend.entity.sysorder.SysUserOrderMgrDTO;
import com.qingcloud.adminbackend.entity.sysorg.SysOrg;
import com.qingcloud.adminbackend.entity.sysorg.SysUserOrg;
import com.qingcloud.adminbackend.entity.user.*;
import com.qingcloud.adminbackend.enums.UserRoleEnum;
import com.qingcloud.adminbackend.service.*;
import com.qingcloud.adminbackend.utils.CommonUtil;
import com.qingcloud.adminbackend.utils.CookieUtil;
import com.qingcloud.base.annotation.LoginUser;
import com.qingcloud.base.constant.SystemConstant;
import com.qingcloud.base.pojo.ApiResult;
import com.qingcloud.base.remote.pojo.LoginUserDTO;
import com.qingcloud.base.remote.pojo.MenuDTO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author luozehua
 * @since 2018-11-19
 */
@RestController
@RequestMapping("/sys-user")
public class SysUserController {

    @Resource
    private ISysUserService sysUserService;

    @Resource
    private ISysOrgService sysOrgService;

    @Resource
    private ISysUserOrgService sysUserOrgService;

    @Resource
    private ISysStationGroupService sysStationGroupService;

    @Resource
    private ISysFunctionService sysFunctionService;

    @Resource
    private ISysOrderService sysOrderService;

    @CloudApi
    @ApiOperation(value = "根据用户名获取用户信息", notes = "根据用户名获取用户信息")
    @GetMapping(value = "/findUserByUserId/{userId}")
    public AjaxResult findUserByUserId(@PathVariable("userId") String userId) {
        LoginUserDTO loginUserDTO = sysUserService.getUserByUserId(userId);
        return AjaxResult.ok(loginUserDTO);
    }

    @CloudApi
    @ApiOperation(value = "获取团队信息", notes = "获取团队信息")
    @GetMapping(value = "/team/{userId}")
    public AjaxResult findTeamInfo(@PathVariable("userId") String userId) {
        UserTeamBO userTeamBO = sysUserService.findTeamInfo(userId);
        return AjaxResult.ok(userTeamBO);
    }

    @CloudApi
    @ApiOperation(value = "保存用户头像地址", notes = "根据用户名获取用户信息")
    @PostMapping(value = "/avatar/save")
    public AjaxResult saveAvatar(@RequestBody UserAvatarBO bo) {
        sysUserService.saveAvatar(bo);
        return AjaxResult.ok();
    }

    @ApiOperation(value = "获取用户详情", notes = "通过用户Id获取用户详情", response = SysUser.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", dataType = "string", paramType = "query",
                    defaultValue = "4028f481585db7d701585dc9f8a00018")
    })
    @GetMapping("/getUserDetails")
    public AjaxResult getUserDetails(String userId) {
        if (CommonUtil.isEmpty(userId)) {
            return new AjaxResult(WamingConstant.FAILURE, "用户Id不能为空", null);
        }
        return new AjaxResult(WamingConstant.SUCCESS, null, sysUserService.getUserDetails(userId));
    }

    /**
     * 过滤无效的role id，防止前端把业务种类提交了
     */
    private void checkRoleId(AddAirUserBO user) {
        if (CollUtil.isNotEmpty(user.getRoleIds())) {
            List<String> ridList = user.getRoleIds().stream().map(Integer::parseInt)
                    .filter(it -> it >= 100 || Integer.valueOf(6).equals(it))
                    .map(String::valueOf)
                    .collect(Collectors.toList());
            user.setRoleIds(ridList);
        }
    }

    @ApiOperation(value = "添加用户", notes = "添加用户")
    @PostMapping(value = "/addAirUser")
    public AjaxResult addAirUser(@RequestBody AddAirUserBO user, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        //过滤无效的role id，防止前端把业务种类提交了
        checkRoleId(user);
        //添加用户
        String saveId = sysUserService.addAirUser(user, userId);
        if (saveId.length() > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("userId", saveId);
            return new AjaxResult(WamingConstant.SUCCESS, "", map);
        } else {
            return new AjaxResult(WamingConstant.FAILURE, "添加失败", "");
        }
    }

    @ApiOperation(value = "更新用户信息", notes = "更新用户信息", response = AddAirUserBO.class)
    @PostMapping(value = "/updateAirUser")
    public AjaxResult updateAirUser(@RequestBody AddAirUserBO user, HttpServletRequest request) {
        //过滤无效的role id，防止前端把业务种类提交了
        checkRoleId(user);
        //更新用户
        String userId = CookieUtil.getUserId(request);
        boolean isAdmin = CookieUtil.isAdmin(request);

        //查询用户客户管理客户
        List<String> mgrList = new ArrayList<>();
        List<String> mgrStationGroup = new ArrayList<>();
        List<String> userAuthFunctions = new ArrayList<>();
        Integer flag = sysUserService.updateAirUser(user, mgrList, mgrStationGroup, userAuthFunctions, userId, isAdmin);
        if (flag > 0) {
            return new AjaxResult(WamingConstant.SUCCESS, "", "修改成功");
        } else {
            return new AjaxResult(WamingConstant.FAILURE, "修改失败", "");
        }
    }

    @ApiOperation(value = "更新蛙鸣用户信息", notes = "更新蛙鸣用户信息", response = AddWmUserBO.class)
    @PostMapping(value = "/updateWmUser")
    public AjaxResult updateWmUser(@RequestBody AddWmUserBO user, HttpServletRequest request) {
        boolean isAdmin = CookieUtil.isAdmin(request);
        String userId = CookieUtil.getUserId(request);
        Map<String, Collection<String>> userAuthFunctions = new HashMap<>();
        List<String> orgTreeByLoginUser = new ArrayList<>();
        Set<String> orders = new HashSet<>();
        Set<String> oamOrders = new HashSet<>();
        List<RoleBusinessBO> roleIds = user.getRoleBusiness();
        //功能列表
        getWmAuthInfo(userId, isAdmin, userAuthFunctions, orgTreeByLoginUser, orders, oamOrders, roleIds);
        Integer flag = sysUserService.updateWmUser(user, orders, orgTreeByLoginUser, oamOrders);
        if (flag > 0) {
            return new AjaxResult(WamingConstant.SUCCESS, "", "修改成功");
        } else {
            return new AjaxResult(WamingConstant.FAILURE, "修改失败", "");
        }
    }

    @ApiOperation(value = "更新蛙鸣用户信息并授权", notes = "更新蛙鸣用户信息并授权", response = AddWmUserBO.class)
    @PostMapping(value = "/updateWmUserAndAuth")
    public AjaxResult updateWmUserAndAuth(@RequestBody AddWmUserBO user, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        boolean isAdmin = CookieUtil.isAdmin(request);
        Map<String, Collection<String>> userAuthFunctions = new HashMap<>();
        List<String> orgTreeByLoginUser = new ArrayList<>();
        Set<String> orders = new HashSet<>();
        Set<String> oamOrders = new HashSet<>();
        List<RoleBusinessBO> roleIds = user.getRoleBusiness();
        //功能列表
        getWmAuthInfo(userId, isAdmin, userAuthFunctions, orgTreeByLoginUser, orders, oamOrders, roleIds);
        Integer flag = sysUserService.updateWmUser(user, orders, orgTreeByLoginUser, oamOrders);
        if (flag > 0) {
            //重新授权
            //更新角色 业务对应
            List<String> stationGroupIds = new ArrayList<>();
            sysUserService.reWmAuth(user, userAuthFunctions, orgTreeByLoginUser, orders, oamOrders, userId, stationGroupIds);
            return new AjaxResult(WamingConstant.SUCCESS, "", "修改成功");
        } else {
            return new AjaxResult(WamingConstant.FAILURE, "修改失败", "");
        }
    }


    @ApiOperation(value = "分页查询空气用户", notes = "分页查询空气用户", response = SysUser.class)
    @PostMapping(value = "/findPageAirUser")
    public AjaxResult findPageAirUser(@RequestBody AirUserBo sysUser, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        boolean isAdmin = CookieUtil.isAdmin(request);
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.findPageAirUser(sysUser, userId, isAdmin));
    }

    @ApiOperation(value = "根据用户ID删除用户", notes = "根据用户ID删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userType", value = "要删除的用户类型 1健康空气用户 2蛙鸣用户", dataType = "string", paramType = "query",
                    defaultValue = "")
    })
    @PostMapping(value = "/deleteUserByIds")
    public AjaxResult deleteUserByIds(@RequestBody List<String> ids, String userType, HttpServletRequest request) {
        if (CollectionUtils.isEmpty(ids)) {
            return new AjaxResult(WamingConstant.FAILURE, "请选择删除用户,删除失败", "删除失败");
        }
        boolean isAdmin = CookieUtil.isAdmin(request);
        String userId = CookieUtil.getUserId(request);
        return sysUserService.deleteUserByIds(ids, userType, isAdmin, userId);
    }

    /**
     * 获取健康用户权限
     *
     * @return
     */
    @ApiOperation(value = "获取健康用户权限", notes = "获取健康用户权限")
    @GetMapping(value = "/getAirUserAuth")
    public AjaxResult getAirUserAuth(@RequestParam String userId) {
        //查询用户所在的用户组
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.getAirUserAuth(userId));
    }


    /**
     * 获取蛙鸣用户权限
     *
     * @return
     */
    @ApiOperation(value = "获取蛙鸣用户权限", notes = "获取蛙鸣用户权限")
    @PostMapping(value = "/getWmUserAuth")
    public AjaxResult getWmUserAuth(@RequestBody WmAuth wmAuth, HttpServletRequest request) {
        String createId = CookieUtil.getUserId(request);
        boolean admin = CookieUtil.isAdmin(request);
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.getWmUserAuth(wmAuth, createId, admin));
    }

    /**
     * 重置密码
     *
     * @return
     */
    @ApiOperation(value = "重置密码", notes = "重置密码")
    @ApiImplicitParam(name = "pwd", value = "{\"userId\":\"\",\"userName\":\"\",\"newPwd\":\"\",\"newPwd_01\":\"\"}", dataType = "Map", paramType = "body")
    @PostMapping(value = "/resetPwd")
    public AjaxResult resetPwd(@Valid @RequestBody UserBO user) {
        Integer flag = sysUserService.resetPwd(user);
        if (flag == -1) {
            return new AjaxResult(WamingConstant.PART_SUCCESS, "新密码或确认密码不能为空", "");
        } else if (flag == -2) {
            return new AjaxResult(WamingConstant.PART_SUCCESS, "新密码与确认密码不匹配", "");
        } else {
            return new AjaxResult(WamingConstant.SUCCESS, "", "密码重置成功");
        }
    }

    @CloudApi
    @ApiOperation(value = "重置自己的密码", notes = "重置自己的密码")
    @PutMapping(value = "/setSelfPwd")
    public ApiResult changePassword(@RequestBody ChangePwdParam param, @LoginUser LoginUserDTO loginUserDTO) {
        param.setUserId(loginUserDTO.getUserId());
        return ApiResult.success(sysUserService.resetSelfPassword(param));
    }

    @ApiOperation(value = "用户禁用", notes = "用户禁用")
    @GetMapping(value = "/userForbidden/{userId}/{isForbidden}")
    public AjaxResult userForbidden(@PathVariable("userId") String userId, @PathVariable("isForbidden") String isForbidden) {
        if ("1".equals(isForbidden)) {
            sysUserService.updateLoginStatus(userId, String.valueOf(SystemConstant.COMMON_ACCOUINT_FORBIDDEN));
        } else {
            sysUserService.updateLoginStatus(userId, String.valueOf(SystemConstant.COMMON_ACCOUINT_QUIT));
        }
        return AjaxResult.success();
    }

    @ApiOperation(value = "解除用户锁定", notes = "解除用户锁定")
    @GetMapping(value = "/userUnlock/{userId}")
    public AjaxResult userUnlock(@PathVariable("userId") String userId) {
        sysUserService.updateLoginStatus(userId, String.valueOf(SystemConstant.COMMON_ACCOUINT_QUIT));
        return AjaxResult.success();
    }

    @ApiOperation(value = "蛙鸣用户授权", notes = "蛙鸣用户授权", response = WmAuthBO.class)
    @PostMapping(value = "/wmUserAuth")
    public AjaxResult wmUserAuth(@RequestBody WmAuthBO userParam, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        boolean isAdmin = CookieUtil.isAdmin(request);
        AddWmUserBO user = new AddWmUserBO();
        BeanUtils.copyProperties(userParam, user);
        Map<String, Collection<String>> userAuthFunctions = new HashMap<>();
        List<String> orgTreeByLoginUser = new ArrayList<>();
        Set<String> orders = new HashSet<>();
        Set<String> oamOrders = new HashSet<>();
        List<RoleBusinessBO> roleIds = user.getRoleBusiness();
        //查询用户客户管理客户
        QueryWrapper<SysUserOrg> query = new QueryWrapper<>();
        query.eq("user_id", userParam.getId());
        String orgId = sysUserOrgService.list(query).get(0).getOrgId();
        //获取登录用户能使用的设备组
        List<String> mgrStationGroup = new ArrayList<>();
        List<SysStationGroup> authStationgroupManage = sysStationGroupService.findAuthStationgroupManage(orgId, userId, isAdmin);
        authStationgroupManage.forEach(e -> mgrStationGroup.add(e.getId()));

        getWmAuthInfo(userId, isAdmin, userAuthFunctions, orgTreeByLoginUser, orders, oamOrders, roleIds);
        sysUserService.reWmAuth(user, userAuthFunctions, orgTreeByLoginUser, orders, oamOrders, userId, mgrStationGroup);
        return new AjaxResult(WamingConstant.SUCCESS, "", "授权成功");
    }

    private void getWmAuthInfo(String userId, boolean isAdmin, Map<String, Collection<String>> userAuthFunctions, List<String> orgTreeByLoginUser, Set<String> orders,
                               Set<String> oamOrders, List<RoleBusinessBO> roleIds) {

        if (!isAdmin) {
            //不是admin，查看是否是完全管理权限
            SysUser sysUser = sysUserService.getById(userId);
            if (WamingConstant.ONE.equals(sysUser.getAdminFlag())) {
                isAdmin = true;
            }
        }
        //功能列表
        if (CollUtil.isNotEmpty(roleIds)) {
            //查询所有角色授权的功能
            Set<String> roleIdSet = roleIds.stream().map(it -> it.getRoleId()).collect(Collectors.toSet());
            //map key是roleId, value是所有functionId
            userAuthFunctions = sysFunctionService.findIdByRoleId(roleIdSet);
        }
        //可管理客户
        List<SysOrg> orgTemp = sysOrgService.getOrgTreeByLoginUser("", userId, isAdmin);
        orgTemp.forEach(e -> orgTreeByLoginUser.add(e.getId()));
        //订单
        SysUserOrderMgrDTO sysUserOrderMgrDTO = new SysUserOrderMgrDTO();
        sysUserOrderMgrDTO.setUserId(userId);
        Set<SysUserOrderMgrDTO> orderTemp = sysOrderService.getOrders(sysUserOrderMgrDTO, isAdmin);
        orderTemp.forEach(e -> orders.add(e.getId()));

        SysUserOrderMgrDTO sysUserOrderMgrDTO2 = new SysUserOrderMgrDTO();
        sysUserOrderMgrDTO2.setUserId(userId);
        sysUserOrderMgrDTO2.setManage(1);
        sysUserOrderMgrDTO2.setRead(1);
        Set<SysUserOrderMgrDTO> ordersTemp2 = sysOrderService.findOrders(sysUserOrderMgrDTO2, isAdmin);
        ordersTemp2.forEach(e -> oamOrders.add(e.getId()));
    }

    /**
     * 健康用户授权
     *
     * @return
     */
    @ApiOperation(value = "健康用户授权", notes = "健康用户授权")
    @PostMapping(value = "/airUserAuth")
    public AjaxResult airUserAuth(@RequestBody AirAuthBO airAuth, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        boolean isAdmin = CookieUtil.isAdmin(request);
        List<String> roleIds = airAuth.getRoleIds();
        String roleId = "-1";
        if (!org.springframework.util.CollectionUtils.isEmpty(roleIds)) {
            roleId = roleIds.get(0);
        }
        //查询用户客户管理客户
        QueryWrapper<SysUserOrg> query = new QueryWrapper<>();
        query.eq("user_id", airAuth.getId());
        String orgId = sysUserOrgService.list(query).get(0).getOrgId();

        List<String> mgrList = new ArrayList<>();
        List<String> mgrStationGroup = new ArrayList<>();
        List<String> userAuthFunctions = new ArrayList<>();
        getAuthInfo(userId, isAdmin, roleId, orgId, mgrList, mgrStationGroup);
        getAuthFunctionInfo(userId, isAdmin, roleId, orgId, userAuthFunctions, "2");
        sysUserService.airUserAuth(airAuth, mgrList, mgrStationGroup, userAuthFunctions, userId, isAdmin);
        return new AjaxResult(WamingConstant.SUCCESS, "", "授权成功");
    }

    private void getAuthFunctionInfo(String userId, boolean isAdmin,
                                     String roleId, String orgId,
                                     List<String> userAuthFunctions,
                                     String menuType) {
        List<MenuDTO> userAuthFunctionsTemp;
        if (!StringUtils.isEmpty(orgId)) {
            userAuthFunctionsTemp = sysFunctionService.getUserAuthFunctions(Arrays.asList(roleId), Arrays.asList(orgId), userId, menuType, isAdmin).getFunctionTree();
        } else {
            userAuthFunctionsTemp = sysFunctionService.getUserAuthFunctions(Arrays.asList(roleId), null, userId, menuType, isAdmin).getFunctionTree();
        }
        //查询所有的孩子
        List<MenuDTO> result = new ArrayList<>();
        findAllFunctions(userAuthFunctionsTemp, result);
        //查询能使用的功能
        result.forEach(e -> {
            userAuthFunctions.add(e.getId());
        });
    }

    /**
     * 查询所有的孩子节点
     *
     * @param userAuthFunctionsTemp
     * @return
     */
    private void findAllFunctions(List<MenuDTO> userAuthFunctionsTemp, List<MenuDTO> result) {
        if (CollUtil.isNotEmpty(userAuthFunctionsTemp)) {
            userAuthFunctionsTemp.forEach(e -> {
                result.add(e);
                List<MenuDTO> childList = e.getChildList();
                if (!CollectionUtils.isEmpty(childList)) {
                    findAllFunctions(childList, result);
                }
            });
        }
    }

    /**
     * 获取登录用户能授权的客户和设备组ID
     *
     * @param userId
     * @param isAdmin
     * @param roleId
     * @param orgId
     * @param mgrList
     * @param mgrStationGroup
     */
    private void getAuthInfo(String userId, boolean isAdmin, String roleId, String orgId, List<String> mgrList, List<String> mgrStationGroup) {
        if (UserRoleEnum.COMPANY_MANAGER_ID.code.toString().equals(roleId)) {
            //企业管理员，授权客户管理权限
            List<SysOrg> orgByUserOrg = sysOrgService.findOrgByUserOrg(orgId, userId, isAdmin);
            orgByUserOrg.forEach(org -> {
                mgrList.add(org.getId());
                List<SysOrg> childSysOrgs = org.getChildSysOrgs();
                childSysOrgs.forEach(e -> mgrList.add(e.getId()));
            });
        } else if (UserRoleEnum.COMPANY_EQUIPMENT_MANAGER_ID.code.toString().equals(roleId)
                || UserRoleEnum.COMPANY_USER_ID.code.toString().equals(roleId)) {
            //企业设备管理员，授权设备管理权限
            //获取登录用户能使用的设备组
            List<SysStationGroup> authStationgroupManage = sysStationGroupService.findAuthStationgroupManage(orgId, userId, isAdmin);
            authStationgroupManage.forEach(e -> mgrStationGroup.add(e.getId()));
        }
    }

    @ApiOperation(value = "检测登录用户名是否已经存在", notes = "检测登录用户名是否已经存在")
    @GetMapping(value = "/userNameExist")
    public AjaxResult userNameExist(@RequestParam String userName) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.userNameExist(userName));
    }

    @ApiOperation(value = "检测登录手机号是否已经存在", notes = "检测登录手机号是否已经存在")
    @GetMapping(value = "/mobilenoExist")
    public AjaxResult mobilenoExist(@RequestParam String mobileno) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.mobilenoExist(mobileno));
    }

    @ApiOperation(value = "检测邮箱是否已经存在", notes = "检测邮箱是否已经存在")
    @GetMapping(value = "/emailExist")
    public AjaxResult emailExist(@RequestParam String email) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.emailExist(email));
    }

    /**
     * 健康用户批量导入
     *
     * @return
     */
    @ApiOperation(value = "健康用户批量导入", notes = "健康用户批量导入")
    @PostMapping(value = "/airUserImport")
    public AjaxResult airUserImport(@RequestParam("excelFile") MultipartFile excelFile,
                                    HttpServletRequest request) {
        if (excelFile != null) {
            String userId = CookieUtil.getUserId(request);
            boolean isAdmin = CookieUtil.isAdmin(request);
            return sysUserService.importUser(excelFile, userId, isAdmin);
        } else {
            return new AjaxResult(3000, "用户批量导入失败", null);
        }
    }

    /**
     * @return
     */
    @ApiOperation(value = "修改用户的用户组", notes = "修改用户的用户组", response = UserBO.class)
    @PostMapping(value = "/updateUser2UserGroup")
    public AjaxResult updateUser2UserGroup(@RequestBody UserBO userBO, HttpServletRequest request) {
        String createId = CookieUtil.getUserId(request);
        int flag = sysUserService.updateUser2UserGroup(userBO, createId);
        if (flag > 0) {
            return new AjaxResult(WamingConstant.SUCCESS, "", "修改成功");
        } else {
            return new AjaxResult(WamingConstant.FAILURE, "修改失败", "");
        }
    }

    @ApiOperation(value = "查询客户下面所有的用户", notes = "查询客户下面所有的用户")
    @ApiImplicitParam(name = "orgId", value = "客户ID", required = true, dataType = "string", paramType = "query")
    @PostMapping(value = "/getUserByOrgId")
    public AjaxResult getUserByOrgId(@RequestParam String orgId) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.getUserByOrgId(orgId));
    }

    @ApiOperation(value = "保存时逐一校验(设备组)", notes = "保存时逐一校验(设备组)")
    @ApiImplicitParam(name = "param", value = "参数：{\"orgId\":\"\",\"stationGroupIds\":\\[\\]}", required = true, dataType = "string", paramType = "query")
    @PostMapping(value = "/checkStationGroupAuth")
    public AjaxResult checkStationGroupAuth(@RequestBody StationGroupBO stationGroupBO) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.checkStaionGroupAuth(stationGroupBO));
    }

    @ApiOperation(value = "登录用户是否有完全管理权限", notes = "登录用户是否有完全管理权限")
    @PostMapping(value = "/hasAllAuth2LoginUser")
    public AjaxResult hasAllAuth2LoginUser(HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        boolean admin = CookieUtil.isAdmin(request);
        return new AjaxResult(WamingConstant.SUCCESS, "", sysUserService.hasAllAuth2LoginUser(userId, admin));
    }

    @ApiOperation(value = "保存修改网格化用户信息数据", notes = "保存修改网格化用户信息数据")
    @PostMapping(value = "/saveGridUserData")
    public AjaxResult saveGridUserData(@RequestBody UserGridDataDTO dto, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        AjaxResult result = sysUserService.saveGridUserData(dto);
        return result;
    }

    @ApiOperation(value = "查询网格化用户信息数据", notes = "保存修改网格化用户信息数据")
    @GetMapping(value = "/selectGridUserData")
    public AjaxResult selectGridUserData(@RequestParam(value = "userId") String userId) {
        UserGridDataDTO vo = sysUserService.selectGridUserData(userId);
        return AjaxResult.ok(vo);
    }

}

